package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.AddSellMapper;
import com.atguigu.spzx.manager.service.AddSellService;
import com.atguigu.spzx.model.dto.sell.sellDto;
import com.atguigu.spzx.model.entity.system.SysUser;
import com.atguigu.spzx.model.vo.sell.SellVo;
import com.atguigu.spzx.utils.AuthContextUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mysql.cj.callback.UsernameCallback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddSellServiceImpl implements AddSellService {

    @Autowired
    private AddSellMapper  addSellMapper;
    @Override
    public void Addsell(sellDto sellDto) {
        SysUser sysUser = AuthContextUtil.get();
        sellDto.setBussnessName(sysUser.getUserName());
        addSellMapper.save(sellDto);
    }

    @Override
    public PageInfo<SellVo> findByPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        SysUser sysUser = AuthContextUtil.get();
        String userName = sysUser.getUserName();
        List<SellVo> list = addSellMapper.findByPage(userName);
        return new PageInfo(list);
    }

    @Override
    public void DeleteSell(Integer id) {
        addSellMapper.DeleteSell(id);
    }

    @Override
    public void UpdateProduct(sellDto sellDto) {
        addSellMapper.UpadateProduct(sellDto);
    }
}
